package batchjob;

/** Contains a column defintion for the SequenceTable. */
public class SequenceTableColumn {

    /** The name/title of the column. */
    public String name;

    RKUVector data;

    /** Create a new column with a given name. */
    public SequenceTableColumn(String aname)
    {
	super();
	name = aname;
	data = new RKUVector();
    }

    /** Get a string representing the data at entry <tt>index</tt>.
	@param index The index of the wanted data.
	@return The result from the stored objects toString method. The
	empty string "" is returned if
	the index is out of bounds or the object at position <tt>index</tt>
	is null.
    */
    public String getReadingAsText(int index)
    {
	if (index>=data.size() || data.elementAt(index)==null)
	    return "";
	else 
	    return ((data.elementAt(index)).toString());
    }

    /** Record a reading in this Column. */
    public void recordData(Object obj)
    {
	data.addElement(obj);
    };

    /** Update the last row. */	
    public void updateLastRow(Object thedata)
    {
	data.setElementAt(thedata, data.size()-1);
    };

    /** Get the columns name. */
    public String getName()
    {
	return name;
    }

    /** Get the number of recorded items. */
    public int size()
    {
	return data.size();
    }

    /** Clear the recorded data. This method will remove all recorded data 
	from this column but not the name. */
    public void clearData()
    {
	data.removeAllElements();
    };
    
    /** Get an array representing the recorded data. */
    public Object[] getDataAsArray()
    {
	return data.getElementsAsArray();
    }

}
